Today we're going to be having a look at animations.
Now, this lecture is probably a slightly bit longer than some of the other lectures in the past few,
some of the other past few lectures, because there's quite a lot to talk about.
Now, animations are absolutely essential in a game, okay.
They really bring life to your game.
And without animations, well, you can have a game that has no animations.
You can get away with using tween servers for some things when it comes to NPCs and stuff, it just
won't feel the same.
And if it was animated, basically other things as well.
Like if you wanted to get players to be able to crouch, to crawl, to crawl under things, to be able
to double jump any stuff like that or any movement of an NPC.
Face it, I used everywhere and aren't the best when you do want to make your own animations.
Now this was something I was debating putting into the previous section, but while but most they're
not too difficult to code, so I wasn't too sure where to put them really in this course, as I could
have put them in the basics in the basic scripting section, but I think it's a good idea learning about
it later on.
Once you've got a good, good understanding as there are, you do need to be familiar with the different
rig types and some other stuff in order to do this, so I might have left it a bit too long maybe.
I'm not too sure, but there wasn't really any perfect place to put this in the course, I don't think.
Really.
Um.
Or even coding an animation, you need to have one.
You need to have an animation made.
Now, um, to make your own animation, you will need to go over to the view section, not the view
section.
Sorry, it's in, um, plugins.
Um.
Where is the animation editor?
Hang on.
Um.
Avatar.
Okay, it's a tab, but it's not in view.
Okay.
Um, so go over to avatar and you have a tab here called the Animation Editor, which if you select
um, is where you control and do any animations.
Let me just put this over here above the output there.
Okay.
So this is your animation editor.
This is where you can edit and do anything with your animation.
Now it currently says here select a rig to animate or create a new rig by selecting Rig Builder under
the avatar section.
So basically you need to select a rig in order to animate and you animate using a rig currently in your
game.
And a rig is just a character in your game basically.
So now you can do import um, in Rig Builder here, which will import some basic rig types here.
Or alternatively, you could go over to plug ins and use a plugin such as character inserts.
Here.
Um, to add a character.
And it was up to you, I'm going to use this method.
And I'm going to start off by setting the rig type to R6.
Remember the rig types are very important R6 six body parts, AR 1515 body parts.
And let's add in just a normal mesh avatar like that there.
So immediately it will be asking you to create an animation name.
So basically the name of your animation clip here, call it whatever you like when name doesn't matter
too much, as long as it's something that you will understand if you're trying to access them.
Um, by via the BBC's homepage.
So I'm going to call this, um, testing.
Animations.
ASX.
Perfect click create.
And there we go.
Here is our animation editor.
All nicely set up.
Now the reason why I'd go for R6 first is because there's less body parts.
It's a lot easier to animate rather than Ar15, so it's good to practicing on your R6 rigs first before
you then go on to Ar15.
Okay, so, um, you might or might not have done animation before on different software.
I'm gonna explain kind of how animation works.
So how it works is that animations are just they're made by via keyframes.
And these keyframes are points in time where you tell or in this case where you tell a rig to be in
this pose.
So it needs to be posed with its arms up, for example, at a certain at a certain point in time.
So certain keyframe, but at another keyframe its arms need to be down.
And then it, then it then moves the, um, its arms so that it will reach the required position at
the keyframe.
And then the second keyframe is the required position back down again.
It's a bit difficult to explain, but I think by showing you it might look a bit better.
So, um, we're going to first click the plus button here, and you can add in different body parts
onto your animation editor, and you can add them in separately if you're wanting to just animate 1
or 2.
But if you want, you're wanting to add more than like if you're wanting to animate more than 2 or 3
body parts, you might as well just add everything in like that there.
So now.
Now everything is included in your animation editor.
What you want to do first is to create a keyframe to start off with.
Now all animations should or not.
Not all, but the majority of animation should start at finish and start and finish at the same point
in time.
So right click on here and click Add Keyframe.
This will add a keyframe.
So over at the.
So as soon as it starts it has this pose here.
We now want to move to timeline to be at a different point in time.
Um, so this can be, for example, um, zero ten out of one.
What does this mean?
Um, this is frames per second.
So one counts per second and it counts for frames.
So this is for temp frame.
And there's 30 frames in a second here.
Easy 29.
And when she reaches 30.
We've been counting that as one second there.
So let's set this to be ten.
I mean, they make a very simple one where it moves his arm up.
Okay, so let's take its left arm here.
Let's select it and you just move it like you would do with any other object.
So you can use the tools.
You can use whatever.
I'm going to move upwards just like that there.
So it's moved its arms up.
And let's do both arms, actually.
And.
Just like that.
Okay.
Not too difficult.
Just rotating them up.
Just like that.
Okay.
Um, so let's see what happens when we click play and you can see its arms move up between those two
keyboards, because at this point its arms need to be down.
At this point its arms need to be up.
So in between its slowly moving those arms just like that there.
That's all it's doing.
It's just moving them between the different keyframes.
You're not telling it where to be every second, but just at a couple of points.
And in between those points, it'll be moving it to the desired position.
Um, now I want this to finish the start and finish at the same point.
So what I can do, I could go over here and rotate it all back into the same position.
Or alternatively, what I could do is select this keyframe by right.
By left clicking right click on it, um, copy and then paste over here at the 20th frame.
Um, again, with animations, it's very important that everything is spaced correctly as well.
So everything is a correct amount of spaces.
So nothing's nothing's moving faster than anything else.
It's all nicely synced up.
And if we play, if we play here, we can see it working quite nicely like that.
If you want the animation to loop on itself, um, you, you obviously want to test out how that looks
when it's looping.
And to do that you can press this button here which will toggle looping.
Click play and see.
It's just going like it's a bird.
So on a fly for example.
Um so yeah.
And you can also pause like that.
You can play this way.
You can play with reverse way.
You can skip to certain keyframes, or you can skip to the start and skip to the end.
So plenty of options there.
Now um, this is the absolute basics for animations.
Okay.
I'm not really going to go into too much more detail because it's not really required as all it is really
is just rotating and moving the existing body parts.
Okay.
Um, so we will probably do a bit of animation, but yeah, we will do a bit of animation when we're
looking at, um, our game after this section.
So you will get a bit of experience in this, but um, it's just moving the characters really.
So nothing too difficult there, nothing too different.
It's just in a slightly different form.
Okay.
Um, so let's say that you've done your animation or whatever and you're ready to move on.
Okay.
Um, you, you now want to click these three dots here.
And this is a very important part here.
So make sure you make sure you're listening here as this could mess up the entire thing.
So I guess one of the reasons why I chose to do animations later on is there's lots of things you can
do wrong, which can mess up an animation.
Um, so one of those things is the animation priority.
Now, what is an animation priority mean?
Well, different not to animations are not necessarily treated equally.
So there are a couple of different types of animation here.
Animation priority.
You have core idle movement and action.
What do these mean?
Well your movement animations are things like your walk, your jump or those kind of things.
Action ones are things like your emote so where you can wave and stuff, um, those emotes will override
any movement animation currently occurring, things also like um, let's say the um.
What could I say to override?
Let's say, I don't know.
There's a banana on the floor, and you want the player to be able to trip over the banana as an animation.
You want that to override any walking animation currently happening, so you'd want to set it as an
action.
So core is the lowest animation priority.
So idle movement or the action types will override your core animation.
So you have idle.
Idle will override core but movement anything above will override idle.
So the ones above it will override the ones below it.
Basically.
Um, now it's set to default as core, which basically means it doesn't work because the idle animation
is playing when the carrot isn't doing anything.
So you literally need no animation playing in order for this to work, which isn't the best at all.
Okay.
Um.
So yeah.
It's not it's not the best really setting it to core as default.
And if you do set it to core on an MPC perhaps, but on your character, it's not going to work.
Now it depends on what you're wanting this to be, but if you're wanting it to be, um, happening when
the player is just still you could be idle movement if you're wanting it to be the player is moving,
but if you're wanting it to be anything which should override the player's movement, which which has
happen no matter what set it's action.
Now I know you've got here action one, two, three and four.
There's not too much difference really.
They added these extra three quite recently.
Um, but just to set it to action, if you don't use the two, three and four, there's nothing that's
going to be overriding it anyway.
So, um, it might take a bit of just practice which one should be best.
Not practice, but a bit of thinking which one should be best.
But just make sure that you're using the best one there.
I'm going to set this one to be action so that it overrides any movement that I do.
Once I've done that, I can then click these dots and save the animation so it's always saved nicely.
Then go ahead and publish my animation to Roblox.
This window here with a title, a description by Wanted To and then click submit which then publishes
my animation.
I can then copy my animation ID which just like anything, the ID is the key bit here you're wanting
to use in studio.
Perfect.
Now we've got our animation nicely working.
Now this should already be a good point where I mentioned one other thing as well, which is another
thing where that can completely mess up your animation.
Mess up your.
So, um, to make this animation in R6, um, if you didn't listen to me or you decided want to try
our 15, then the animation will only work on 15 characters.
Basically, if you make an animation using an R6 rig, it will only work on R6 rigs.
And if you make an animation using an R 16 rig.
So R 16, that's not that's not a thing and r 15 rig, then it will only work on R 15 rigs.
So just be careful which one you're using and some some games.
There's there's two ways you can ways you can.
He and R6 or R6 body type, but if you are allowing both, you will have to make two animations for
everything one for R6, one for Ar15.
Check the play, check the rig type of the humanoid before you.
Then go ahead and do anything else.
So just keep an eye for that one there.
Okay, let's get the output back open.
Um, let's be important.
Cool.
And let's go and have a go at coding this animation.
So um, let's go into let's go.
Let's start by coding NPCs first so they're slightly easier to code.
So in here we're going to add a um we'll just be done locally.
Um no this can be done by everyone.
Everyone needs to see the animation.
And we're going to add our animation as an animation object, so you can add it wherever you'd like.
I'm going to add inside the script so it's easier to add in an animation object there.
And then the animation ID you're going to paste in there your animation ID and.
Using a table.
So local animation is equal to script dot not parent sorry dot animation.
Okay.
You now want to reference the humanoid of the rig.
That's very important.
Referencing the humanoid.
So we're going to reference local rig is equal to script dot parents and local humanoid is equal to
rig.
Colon rig for child humanoid.
Remember, humanoid takes a bit longer to load anything else.
So we're going to put wait for child.
Now you might think well we've got the animation.
Why can't we just say animation?
Colon play.
Like that there, and that would absolutely be a possibility we could do.
But it doesn't work.
Okay.
And I'll be honest, when I first probably when I first, um, was trying out animations, I did it
that way as well.
Why is it not working?
Um, but they were a bit more.
They, it was an extra step before you can do that.
So just because you have an animation does not mean it is loaded.
So you need to first load the animation onto the humanoid so that the humanoid can then play your animation.
So it's almost like you've got a game you've bought as a disc from a shop, for example.
You can't just go ahead and put it into a console or put it into a computer and play that game.
You then you first need to load the game and install the game.
That's kind of what it's going.
It's it's taking the information from that onto your console, in this case onto the humanoid in order
for it to be able to play it.
And when it does this, we in the in the proper scripting terms, we are creating an animation track.
So you don't play the animation, you play the animation track.
And that's another, another bit where a lot of people get confused on is playing is what, what is
why can't you play the animation?
You have to be playing the animation track.
So let's make one of those.
So local animation track is equal to humanoid colon load animation there.
And we're going to load this animation like that there.
And now I've got all that we can play our animation track.
So let's just wait a few seconds so we can see what's happening and say animation track colon play like
that there.
And also is worth noticing if you if you start writing animation colon play, it doesn't come up on
the autocomplete feature.
So autocomplete is also a good method to figure out if what you're writing is correct.
That's not doesn't necessarily always mean if autocomplete autocomplete isn't working, but you're writing
something wrong.
But you should definitely double check before you continue.
Okay, and let's try this out now.
Um, animation is always a bit difficult to set up, so I'm going to hope this works.
If not, I've got a couple of things I could perhaps change, um, if there are any issues.
Hopefully after about five seconds it.
Yeah, perfect.
It's doing our nice animation there.
And there you go.
That's how you can animate rigs.
Um, in your in your game.
Okay.
Now what was a bit unsure about is if I go into game settings here and go under avatar.
Um.
Oh, it's our 15.
That's strange.
Oh, no.
Sorry.
I'm completely getting myself confused here.
Basically, if you want to, um, if you want to animate players, which we're going to have a look
at just in a minute.
Now, um, this has to be set to the correct type that your animation is off, basically.
But for NPCs it can be a beaver type, which is fine.
Okay, cool.
Um, let's now then have a look at how how we animate players.
Now, animating players might sound a bit difficult because they already have animation, so you have
to kind of get rid of those and then um, yeah, get rid of those, then add your own ones and find
out when the player is walking and playing.
The animations override lots of complicated scripts.
Well, funnily enough, that's all been coded already for us.
Um, so if we go into our my player here, so in the character here, there's this local script called
animate.
And if you open it up, this entire script here controls everything that I said there.
So it overrides all the other stuff that you need to write to there.
Now, um, we don't really want to be making any edits to this script because it works completely fine.
And it's not a good idea messing with Roblox core scripts.
Um, but what you can do, however, is inside the animate.
There's lots of different IDs.
These are the IDs of all your animations, so all you need to do really is get one of these.
For example, let's take let's take run.
Go inside it and there's a run animation object which has the animation ID.
So all you need to do is put that in there and you then change the running animation just like that.
Um, now some of them have called different things.
So for example walk is walk anim run is run anim.
But if we go into idle it's animation one.
Animation two.
So the names aren't very consistent.
So do just be careful with that.
Um but that would basically be the method in order to do that.
So instead of writing all lots of complicated animation scripts, we only need to add some simple code
here.
So let's add a script into server script service.
Um, let's use the player added function.
So event sorry.
So game dot players player added connect function player like that there reference the character.
So um.
Could we do this?
Let's say, um, player dot character.
Um.
Cat added kurdan weights.
Local character is equal to player character.
Local humanoid.
Again, we need the humanoid to do any kind of animation.
Humanoid is equal to character.
Curl on.
Wait for child.
Humanoid.
Can spell it right.
There we go.
And, um, we also want to reference that animation script.
So animate script.
Is equal.
Is equal to character.
Colon weight per child.
Now this animation script again takes a bit longer to load.
But anything else?
It's just called animate.
Like this here.
So, um, not not too difficult to reference, but just make sure it's the exact spelling there, because
if you spell it wrong, it won't be referencing that script.
Snap access the script.
All we need to do is to change values that change the values inside of the script.
Now we're not going to make any kind of walking and running animations.
They take a bit longer to load, a bit longer to make any kind of good ones.
So instead I'm going to change the running animation to be the flapping thing.
So we'll see how that works.
So we're going to get animate script.
Now I'd recommend the time you may you may be run the game a few times just not play the game to see
what all these objects are called.
Or you can duplicate the script and put it into the workspace just to see what all the objects are called.
I've got it written down.
It's to change the running animation.
It's it's dot run dot run anim.
But again it's not consistent and it's different for different animations you're wanting to change.
Just be careful of that okay.
Um the animation ID is equal to and I'm going to put in there my ID written like that.
Okay.
And let's just go ahead and try this out.
So let's play the game and see what I've done to my moving animation.
So I was completely fine.
And when I walk okay, this is a sign that probably it's.
It was hour 15 wasn't it?
Game settings avatar okay, change avatar type here to be R6.
That's fine.
Yes.
Um, now hopefully it will work.
If not, there's still a couple other things I think could be changing here.
Doesn't like my, um, doesn't like my clothing because it's R6 only.
Oh.
Okay, let's check the.
Okay.
One more thing I think I could do is to, um, write down.
What is it?
Hang on.
If I add an animation.
Paste this in.
It puts this bit at the front.
Copying this entire thing and writing out instead of just the number like that.
Um, sometimes it just it's just it's a bit easier because that's how it treats it in the animation.
If you put in the number, it autocomplete it to that.
But then there might be necessarily there might, there could be an issue to do with that.
Um, so let's try this out again.
Hopefully now it'll be working.
Ooh.
It's not.
Um.
Why might this not be working?
Um.
Play.
Added player play.
Added character weights.
Humanoids.
Have I done my own error?
No.
Because it's it's not.
We don't need to add in a, um, animation controller with a child.
Animate animate script .1.1 anim.
The animation id is equal to this.
Let's make sure this is the correct one.
So um.
Over here.
Animate run.
Von einem 145.
Yep.
So it's a correct one written there.
So I've set this to be the case, but it's not wanting to change it.
Hm.
Let's also try and change the walking animation.
Perhaps.
So basic.
Animate script.
Dot walk.
Anim dot animation.
ID is equal to.
Let's say it's the same thing.
Listed here.
I've always found animations a little bit tricky personally.
Um.
Let's see.
Hopefully this will work.
There we go.
Perfect.
So I think maybe because, um, I needed to set both walking and running, because depending on the
speed that you're walking, I guess depending on the speed that you're moving, it'll either be walking
or running.
So idle is completely the same.
But when we're walking, it's a nice flapping animation there.
This just looks stupid, but it gives you a good example here of some of the animations that you can
choose from.
Um, so yeah, there you go.
So um, it's just updating these values in the animation script, but for animating the character and
NPCs, it's creating an animation track and playing that animation track.
Um, so quite a lot of stuff here with animations and animations are very key parts, but managed to
do it just in one lecture.
You will get more practice on creating some of these animations.
Um, in when we have a go at making our game later on, but definitely have practice.
The reason why I'm not doing too much on those is because, well, this is a scripting section, not
a, um, not like a building section where we're looking at, um, building characters and things like
that.
And it's nothing new, really.
It's just sometimes a bit I think it's more practice, really.
Animations.
Um, and maybe, um, a bit of inspiration as well.
But yeah, definitely try out some.
Making some cool animations.
Animations can look really cool and um, try just using a couple R6 ones before you move on to AR 15.
As AR 15 is a little bit more complicated, code it the exact same exact same way.
There's just more body parts for you to move.
So, um, there's more for you to change as each keyframe, but it allows more possibilities, so have
fun.
Those animations are really cool.
Um, and now you also know how to write whatever code and stuff there was there.
If I was introduced to you these last section and then you have to wait like, um, a couple hours worth
of content before you even learn how to script them.
I think it would be a bit pointless.
Um, that's why I decided to do it all in one lesson.
So, um, if you watched All the way, that's really good.
It's quite, probably quite, quite a long, a longer lecture and, um, have a play around with animations
and.
Yeah, join me in the next, during the next lecture, um, where we're going to have a look at, um,
keyframes, a whole new different area here about keyframes.
So join me in the next in the next lecture for that.